package com.zone.gateway.sdk.listener;

import com.zone.gateway.common.Constant;
import com.zone.gateway.sdk.config.ApiGatewaySdkProperties;
import com.zone.gateway.sdk.domain.service.RedisMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;

/**
 * @author: zongzi
 * @description: 应用启动完成消息
 * @date: 2025/4/30
 */
public class ApplicationStartedCustomerListener implements ApplicationListener<ApplicationReadyEvent> {
    private final Logger logger = LoggerFactory.getLogger(ApplicationStartedCustomerListener.class);

    private final ApiGatewaySdkProperties properties;

    private final RedisMessageService redisMessageService;

    public ApplicationStartedCustomerListener(ApiGatewaySdkProperties properties, RedisMessageService redisMessageService) {
        this.properties = properties;
        this.redisMessageService = redisMessageService;
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        // 应用启动完毕，通知gateway center接口已经注册完成
        redisMessageService.publish(properties.getGatewayCenterUrl(), Constant.RPC_REGISTER_CHANNEL, properties.getSystemId());
    }
}
